home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Admin / ad_imagemacros.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  16.1 KB  |  605 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Skin -> Image Macro functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 4th April 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25.  
  26.  
  27.  
  28. $idx = new ad_settings();
  29.  
  30.  
  31. class ad_settings {
  32.  
  33.     var $base_url;
  34.  
  35.     function ad_settings() {
  36.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  37.  
  38.         switch($IN['code'])
  39.         {
  40.             case 'wrapper':
  41.                 $this->list_current();
  42.                 break;
  43.                 
  44.             case 'add':
  45.                 $this->add_images();
  46.                 break;
  47.                 
  48.             case 'edit':
  49.                 $this->do_form('edit');
  50.                 break;
  51.                 
  52.             case 'doadd':
  53.                 $this->save_wrapper('add');
  54.                 break;
  55.                 
  56.             case 'doedit':
  57.                 $this->save_wrapper('edit');
  58.                 break;
  59.                 
  60.             case 'remove':
  61.                 $this->remove();
  62.                 break;
  63.                 
  64.             case 'export':
  65.                 $this->export();
  66.             
  67.             //-------------------------
  68.             default:
  69.                 $this->list_current();
  70.                 break;
  71.         }
  72.         
  73.     }
  74.     
  75.     
  76.     
  77.     function export()
  78.     {
  79.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  80.         
  81.         if ($IN['id'] == "")
  82.         {
  83.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  84.         }
  85.         
  86.         //+-------------------------------
  87.         
  88.         $DB->query("SELECT * from ibf_images WHERE imid='".$IN['id']."'");
  89.         
  90.         if ( ! $row = $DB->fetch_row() )
  91.         {
  92.             $ADMIN->error("Could not query the information from the database");
  93.         }
  94.         
  95.         //+-------------------------------
  96.         
  97.         $archive_dir   = $INFO['base_dir']."/archive_out";
  98.         $images_dir    = $INFO['base_dir']."/style_images/".$row['imid'];
  99.         
  100.         require $root_dir."sources/lib/tar.php";
  101.         
  102.         if (!is_dir($archive_dir))
  103.         {
  104.             $ADMIN->error("Could not locate $archive_dir, is the directory there?");
  105.         }
  106.         
  107.         if (!is_writeable($archive_dir))
  108.         {
  109.             $ADMIN->error("Cannot write in $archive_dir, CHMOD via FTP to 0755 or 0777 to enable this script to write into it. IBF cannot do this for you");
  110.         }
  111.         
  112.         if (!is_dir($images_dir))
  113.         {
  114.             $ADMIN->error("Could not locate $images_dir, is the directory there?");
  115.         }
  116.         
  117.         //+-------------------------------
  118.         // Attempt to copy the files to the
  119.         // working directory...
  120.         //+-------------------------------
  121.         
  122.         $l_name = preg_replace( "/\s{1,}/", "_", $row['setname'] );
  123.         
  124.         $new_dir = "image-".$l_name;
  125.         
  126.         if ( ! $ADMIN->copy_dir($images_dir, $archive_dir."/".$new_dir) )
  127.         {
  128.             $ADMIN->error( $ADMIN->errors );
  129.         }
  130.         
  131.         // Generate the config file..
  132.         
  133.         $file_content = "<?php\n\n";
  134.         
  135.         foreach($row as $k => $v)
  136.         {
  137.         
  138.             $v = preg_replace( "#style_images/".$row['imid']."/#", "style_images/%img_dir%/", $v );
  139.         
  140.             $file_content .= "\n\$config['$k'] = \"".addslashes($v)."\";";
  141.         }
  142.         
  143.         $file_content .= "\n\n?".">";
  144.         
  145.         $FH = fopen($archive_dir."/".$new_dir."/"."conf.inc", 'w');
  146.         fwrite($FH, $file_content, strlen($file_content));
  147.         fclose($FH);
  148.         
  149.         // Add files and write tarball
  150.         
  151.         $tar = new tar();
  152.         
  153.         $tar->new_tar( $archive_dir, $new_dir.".tar" );
  154.         $tar->add_directory( $archive_dir."/".$new_dir );
  155.         $tar->write_tar();
  156.         
  157.         // Check for errors.
  158.         
  159.         if ($tar->error != "")
  160.         {
  161.             $ADMIN->error($tar->error);
  162.         }
  163.         
  164.         // remove original unarchived directory
  165.         
  166.         $ADMIN->rm_dir($archive_dir."/".$new_dir);
  167.         
  168.         $ADMIN->done_screen("Template Pack Export Created<br><br>You can download the tar-chive <a href='archive_out/{$new_dir}.tar' target='_blank'>here</a>", "Manage Template Sets", "act=templ" );
  169.         
  170.         
  171.     }
  172.     
  173.     //-------------------------------------------------------------
  174.     // Add images..
  175.     //-------------------------------------------------------------
  176.     
  177.     
  178.     function add_images()
  179.     {
  180.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  181.         
  182.         if ($IN['id'] == "")
  183.         {
  184.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  185.         }
  186.         
  187.         //-------------------------------------
  188.         
  189.         if ( ! is_writeable($root_path.'style_images') )
  190.         {
  191.             $ADMIN->error("The directory 'style_images' is not writeable by this script. Please check the permissions on that directory. CHMOD to 0777 if in doubt and try again");
  192.         }
  193.         
  194.         //-------------------------------------
  195.         
  196.         if ( ! is_dir($root_path.'style_images/'.$IN['id']) )
  197.         {
  198.             $ADMIN->error("Could not locate the original image set to copy, please check and try again");
  199.         }
  200.         
  201.         //-------------------------------------
  202.         
  203.         $DB->query("SELECT * FROM ibf_images WHERE imid='".$IN['id']."'");
  204.         
  205.         //-------------------------------------
  206.         
  207.         if ( ! $row = $DB->fetch_row() )
  208.         {
  209.             $ADMIN->error("Could not query that image set from the DB, so there");
  210.         }
  211.         
  212.         //-------------------------------------
  213.         
  214.         $row['setname'] = $row['setname'].".2";
  215.         
  216.         // Insert a new row into the DB...
  217.         
  218.         $final = array();
  219.         
  220.         foreach($row as $k => $v)
  221.         {
  222.             if ($k == 'imid')
  223.             {
  224.                 continue;
  225.             }
  226.             else
  227.             {
  228.                 $final[ $k ] = $v;
  229.             }
  230.         }
  231.         
  232.         $db_string = $DB->compile_db_insert_string( $final );
  233.         
  234.         $DB->query("INSERT INTO ibf_images (".$db_string['FIELD_NAMES'].") VALUES(".$db_string['FIELD_VALUES'].")");
  235.         
  236.         $new_id = $DB->get_insert_id();
  237.         
  238.         //-------------------------------------
  239.         
  240.         if ( ! $ADMIN->copy_dir( $INFO['base_dir'].'style_images/'.$IN['id'] , $INFO['base_dir'].'style_images/'.$new_id ) )
  241.         {
  242.             $DB->query("DELETE FROM ibf_images WHERE imid='$new_id'");
  243.             
  244.             $ADMIN->error( $ADMIN->errors );
  245.         }
  246.         
  247.         //-------------------------------------
  248.         // Pass to edit / add form...
  249.         //-------------------------------------
  250.         
  251.         $this->do_form('add', $new_id);
  252.     
  253.     }
  254.     
  255.     //-------------------------------------------------------------
  256.     // REMOVE WRAPPERS
  257.     //-------------------------------------------------------------
  258.     
  259.     function remove()
  260.     {
  261.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  262.         
  263.         //+-------------------------------
  264.         
  265.         
  266.         if ($IN['id'] == "")
  267.         {
  268.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  269.         }
  270.         
  271.         $dir_to_remove = $INFO['base_dir']."style_images/".$IN['id'];
  272.         
  273.         if ( SAFE_MODE_ON == 0 )
  274.         {
  275.             if ( $ADMIN->rm_dir( $dir_to_remove ) )
  276.             {
  277.             
  278.                 $DB->query("DELETE FROM ibf_images WHERE imid='".$IN['id']."'");
  279.                 
  280.                 $std->boink_it($SKIN->base_url."&act=image");
  281.                 exit();
  282.             }
  283.             else
  284.             {
  285.                 $ADMIN->error("Could not remove the image pack files, please check the CHMOD permissions to ensure that this script has the correct permissions to allow this");
  286.             }
  287.         }
  288.         else
  289.         {
  290.             $DB->query("DELETE FROM ibf_images WHERE imid='".$IN['id']."'");
  291.             $ADMIN->info_screen("Safe mode has been detected and this script cannot remove the images and directories for you, please remove the directory '$dir_to_remove' via FTP. The data has been removed from the database successfully");
  292.         }
  293.     }
  294.     
  295.     
  296.     
  297.     //-------------------------------------------------------------
  298.     // ADD / EDIT IMAGE SETS
  299.     //-------------------------------------------------------------
  300.     
  301.     function save_wrapper()
  302.     {
  303.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP, $HTTP_POST_VARS;
  304.         
  305.         //+-------------------------------
  306.         
  307.         if ($IN['id'] == "")
  308.         {
  309.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  310.         }
  311.     
  312.         
  313.         if ($IN['setname'] == "")
  314.         {
  315.             $ADMIN->error("You must specify a name for this image and macro set");
  316.         }
  317.         
  318.         $barney = array();
  319.         
  320.         foreach ($IN as $k => $v)
  321.         {
  322.             if ( preg_match( "/^XX_(\S+)$/", $k, $match ) )
  323.             {
  324.                 if ( isset($IN[ $match[0] ]) )
  325.                 {
  326.                     $v = preg_replace( "/'/", "'", stripslashes($HTTP_POST_VARS[ $match[0] ]) );
  327.                 
  328.                     $barney[ $match[1] ] = $v;
  329.                 }
  330.             }
  331.         }
  332.         
  333.         if ( count($barney) < 10 )
  334.         {
  335.             $ADMIN->error("Oopsie, something has gone wrong - did you leave all the fields blank?");
  336.         }
  337.         
  338.         $barney['setname'] = $IN['setname'];
  339.         
  340.         $db_string = $DB->compile_db_update_string( $barney );
  341.         
  342.         $DB->query("UPDATE ibf_images SET $db_string WHERE imid='".$IN['id']."'");
  343.         
  344.         $ADMIN->done_screen("Set updated", "Manage Image and Macro Sets", "act=image" );
  345.         
  346.         
  347.         
  348.     }
  349.     
  350.     //-------------------------------------------------------------
  351.     // ADD / EDIT MACRO SETS
  352.     //-------------------------------------------------------------
  353.     
  354.     function do_form( $type='add', $id="" )
  355.     {
  356.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  357.         
  358.         //+-------------------------------
  359.         
  360.         if ($id != "")
  361.         {
  362.             $IN['id'] = $id;
  363.         }
  364.         
  365.         //+-------------------------------
  366.         
  367.         if ($IN['id'] == "")
  368.         {
  369.             $ADMIN->error("You must specify an existing image set ID, go back and try again");
  370.         }
  371.         
  372.         //+-------------------------------
  373.         
  374.         $DB->query("SELECT * from ibf_images WHERE imid='".$IN['id']."'");
  375.         
  376.         if ( ! $row = $DB->fetch_row() )
  377.         {
  378.             $ADMIN->error("Could not query the information from the database");
  379.         }
  380.         
  381.         if ($type == 'add')
  382.         {
  383.             $button = 'Update Image & Macro set';
  384.             
  385.             foreach( $row as $k => $v )
  386.             {
  387.                 $v = preg_replace( "#style_images/(\d+)/#", "style_images/".$IN['id']."/", $v );
  388.                 
  389.                 $row[$k] = $v;
  390.             }
  391.             
  392.         }
  393.         else
  394.         {
  395.             $button = 'Edit Image & Macro set';
  396.         }
  397.         
  398.         //+-------------------------------
  399.     
  400.         $ADMIN->page_detail = "You may use edit the macros that power the images. You do not have to use an image, you may use text, flash or other objects.";
  401.         $ADMIN->page_title  = "Manage Image & Macro sets";
  402.         
  403.         //+-------------------------------
  404.         
  405.         
  406.         $ADMIN->html .= $SKIN->js_no_specialchars();
  407.         
  408.         
  409.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'doedit'    ),
  410.                                                   2 => array( 'act'   , 'image'     ),
  411.                                                   3 => array( 'id'    , $IN['id']   ),
  412.                                          ), "theAdminForm", "onSubmit=\"return no_specialchars('images')\""       );
  413.                                          
  414.         //+-------------------------------
  415.         
  416.         $SKIN->td_header[] = array( " "   , "20%" );
  417.         $SKIN->td_header[] = array( " "   , "80%" );
  418.  
  419.         //+-------------------------------
  420.         
  421.         $ADMIN->html .= $SKIN->start_table( "Image & Macro set title" );
  422.         
  423.         $ADMIN->html .= $SKIN->add_td_row( array( 
  424.                                                     "Image & Macro Set Title",
  425.                                                     $SKIN->form_input('setname', $row['setname']),
  426.                                          )      );
  427.                                          
  428.         $ADMIN->html .= $SKIN->end_table();
  429.                                          
  430.         //+-------------------------------
  431.         
  432.         $SKIN->td_header[] = array( "Macro"    , "20%" );
  433.         $SKIN->td_header[] = array( "Source"   , "60%" );
  434.         $SKIN->td_header[] = array( "Current"  , "20%" );
  435.  
  436.         //+-------------------------------
  437.         
  438.         $ADMIN->html .= $SKIN->start_table( "Current Macros" );
  439.                                          
  440.         foreach($row as $k => $v)
  441.         {
  442.             if ($k != 'imid' && $k != 'setname')
  443.             {
  444.                 if ( ! preg_match( "/^\d+$/", $k ) )
  445.                 {
  446.                 
  447.                     $real = preg_replace( "/'/", "'", $v );
  448.                 
  449.                     $ADMIN->html .= $SKIN->add_td_row( array( 
  450.                                                         "$k",
  451.                                                         $SKIN->form_input('XX_'.$k, $real),
  452.                                                         "$v",
  453.                                              )      );
  454.                 }
  455.             }
  456.         }
  457.                                          
  458.  
  459.                                                  
  460.         $ADMIN->html .= $SKIN->end_form($button);
  461.                                          
  462.         $ADMIN->html .= $SKIN->end_table();
  463.         
  464.         //+-------------------------------
  465.         //+-------------------------------
  466.         
  467.         $ADMIN->output();
  468.         
  469.         
  470.     }
  471.     
  472.     //-------------------------------------------------------------
  473.     // SHOW WRAPPERS
  474.     //-------------------------------------------------------------
  475.     
  476.     function list_current()
  477.     {
  478.         global $IN, $root_path, $INFO, $DB, $SKIN, $ADMIN, $std, $MEMBER, $GROUP;
  479.         
  480.         $form_array = array();
  481.     
  482.         $ADMIN->page_detail = "Images and Macros are used in the skin templates as shorthand for an image or other style information. This enables you to use text links instead of buttons or flash movies for certain images. An image and macro set contains the actual images and the macros to power them.";
  483.         $ADMIN->page_title  = "Manage Image and Macros";
  484.         
  485.         //+-------------------------------
  486.         
  487.         $SKIN->td_header[] = array( "Title"        , "40%" );
  488.         $SKIN->td_header[] = array( "Allocation"   , "30%" );
  489.         $SKIN->td_header[] = array( "Export"       , "10%" );
  490.         $SKIN->td_header[] = array( "Edit"         , "10%" );
  491.         $SKIN->td_header[] = array( "Remove"       , "10%" );
  492.         
  493.         //+-------------------------------
  494.         
  495.         $DB->query("SELECT DISTINCT(s.img_id), i.imid, i.setname, s.sname from ibf_images i, ibf_skins s WHERE s.img_id=i.imid ORDER BY i.setname ASC");
  496.         
  497.         $used_ids = array();
  498.         $show_array = array();
  499.         
  500.         if ( $DB->get_num_rows() )
  501.         {
  502.         
  503.             $ADMIN->html .= $SKIN->start_table( "Current Image & Macro sets In Use" );
  504.             
  505.             while ( $r = $DB->fetch_row() )
  506.             {
  507.             
  508.                 $show_array[ $r['imid'] ] .= stripslashes($r['sname'])."<br>";
  509.             
  510.                 if ( in_array( $r['imid'], $used_ids ) )
  511.                 {
  512.                     continue;
  513.                 }
  514.                 
  515.                 $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['setname'])."</b>",
  516.                                                           "<#X-{$r['imid']}#>",
  517.                                                           "<center><a href='".$SKIN->base_url."&act=image&code=export&id={$r['imid']}'>Export</a></center>",
  518.                                                           "<center><a href='".$SKIN->base_url."&act=image&code=edit&id={$r['imid']}'>Edit</a></center>",
  519.                                                           "<i>Deallocate before removing</i>",
  520.                                                  )      );
  521.                                                    
  522.                 $used_ids[] = $r['imid'];
  523.                 
  524.                 $form_array[] = array( $r['imid'], $r['setname'] );
  525.                 
  526.             }
  527.             
  528.             foreach( $show_array as $idx => $string )
  529.             {
  530.                 $string = preg_replace( "/<br>$/", "", $string );
  531.                 
  532.                 $ADMIN->html = preg_replace( "/<#X-$idx#>/", "$string", $ADMIN->html );
  533.             }
  534.             
  535.             $ADMIN->html .= $SKIN->end_table();
  536.         }
  537.         
  538.         if ( count($used_ids) > 0 )
  539.         {
  540.         
  541.             $DB->query("SELECT imid, setname FROM ibf_images WHERE imid NOT IN(".implode(",",$used_ids).")");
  542.         
  543.             if ( $DB->get_num_rows() )
  544.             {
  545.             
  546.                 $SKIN->td_header[] = array( "Title"  , "70%" );
  547.                 $SKIN->td_header[] = array( "Export" , "10%" );
  548.                 $SKIN->td_header[] = array( "Edit"   , "10%" );
  549.                 $SKIN->td_header[] = array( "Remove" , "10%" );
  550.             
  551.                 $ADMIN->html .= $SKIN->start_table( "Current Unallocated Image & Macro sets" );
  552.                 
  553.                 $ADMIN->html .= $SKIN->js_checkdelete();
  554.                 
  555.                 while ( $r = $DB->fetch_row() )
  556.                 {
  557.                     
  558.                     $ADMIN->html .= $SKIN->add_td_row( array( "<b>".stripslashes($r['setname'])."</b>",
  559.                                                               "<center><a href='".$SKIN->base_url."&act=image&code=export&id={$r['imid']}'>Export</a></center>",
  560.                                                               "<center><a href='".$SKIN->base_url."&act=image&code=edit&id={$r['imid']}'>Edit</a></center>",
  561.                                                               "<center><a href='javascript:checkdelete(\"act=image&code=remove&id={$r['imid']}\")'>Remove</a></center>",
  562.                                                      )      ); 
  563.                                                      
  564.                     $form_array[] = array( $r['imid'], $r['setname'] );
  565.                                                        
  566.                 }
  567.                 
  568.                 $ADMIN->html .= $SKIN->end_table();
  569.             }
  570.         }
  571.         
  572.         //+-------------------------------
  573.         //+-------------------------------
  574.         
  575.         $ADMIN->html .= $SKIN->start_form( array( 1 => array( 'code'  , 'add'     ),
  576.                                                   2 => array( 'act'   , 'image'    ),
  577.                                          )      );
  578.         
  579.         $SKIN->td_header[] = array( " "  , "40%" );
  580.         $SKIN->td_header[] = array( " "  , "60%" );
  581.         
  582.         $ADMIN->html .= $SKIN->start_table( "Create New Image & Macro Set" );
  583.             
  584.         //+-------------------------------
  585.         
  586.         $ADMIN->html .= $SKIN->add_td_row( array( "<b>Base new Image & Macro set on...</b><br>(Note: This will also copy the images)" ,
  587.                                                     $SKIN->form_dropdown( "id", $form_array)
  588.                                  )      );
  589.         
  590.         $ADMIN->html .= $SKIN->end_form("Create new Image & Macro set");
  591.                                          
  592.         $ADMIN->html .= $SKIN->end_table();
  593.         
  594.         //+-------------------------------
  595.         //+-------------------------------
  596.         
  597.         $ADMIN->output();
  598.     
  599.     }
  600.     
  601.     
  602. }
  603.  
  604.  
  605. ?>